package com.hrt.manage.access.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.Role;
import com.hrt.bean.RoleAccess;
import com.hrt.bean.ViewResource;
import com.hrt.manage.access.dao.AccessDao;
import com.hrt.manage.access.service.AccessService;
import com.hrt.manage.menus.dao.ViewResourceDao;

@Service
public class AccessServiceImpl implements AccessService {

	
	@Autowired
	private AccessDao dao;
	
	@Autowired
	private ViewResourceDao viewResDao;
	
	
	@Override
	public List<Role> queryRolesByUserId(Long userId) {
		// TODO Auto-generated method stub
		List<Role> roles=new ArrayList<Role>();
		//roles=dao.queryRolesByUserId(userId);
		return roles;
	}

	@Override
	public List<ViewResource> queryAccByRole(Long roleId) {
		// TODO Auto-generated method stub
		List<ViewResource> access=new ArrayList<ViewResource>();
		access=viewResDao.queryViewResByRole(roleId);
		return access;
	}

	@Override
	public List<ViewResource> queryAccByScope(Long roleId, Integer scope) {
		List<ViewResource> access=new ArrayList<ViewResource>();
		
		access=dao.queryAccByScope( roleId,  scope);
		return access;
	}

	@Transactional
	@Override
	public void deleteOldResource(List<ViewResource> oldResource) {
		for(ViewResource vr:oldResource){
			if(vr!=null){
				dao.deleteEntity(vr.getId());
			}
		}
		
	}

}
